import {
  createStore
} from 'vuex'
import api from '../api/cart'
export default createStore({
  state: {
    cartCount: 0
  },
  mutations: {
    addCart(state, payload) {
      state.cartCount = payload.count;
    },
    updateCartList(state, payload) {
      state.cartList = payload
    },
  },
  actions: {
    async updateCart(ctx) {
      const {
        data
      } = await api.getCart();
      ctx.commit('addCart', {
        count: data.length || 0
      })
    }
  },
  modules: {}
})